﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TestImport.Model.DatabaseRepositories
{
    public abstract partial class DatabaseRepository
    {
        /****************/
        /* LeerlingItem */
        /****************/

        public DataTable LeveringItem_GetData()
        {
            return defaultExecuteReaderDataTable(CommandType.Text, "SELECT leveringItemID, leveringID, boekID, aantal, status FROM LeveringItem");
        }

        public void LeveringItem_InsertLeveringItem(int leveringID, int boekID, int aantal, bool status)
        {
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(4);
                dbManager.AddParameters(0, "@leveringID", leveringID);
                dbManager.AddParameters(1, "@boekID", boekID);
                dbManager.AddParameters(2, "@aantal", aantal);
                dbManager.AddParameters(3, "@status", status);
                dbManager.ExecuteNonQuery(CommandType.Text, "INSERT INTO LeveringItem (leveringID, boekID, aantal, status) VALUES (@leveringID, @boekID, @aantal, @status)");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public bool LeveringItem_Truncate()
        {
            bool succeed = false;
            try
            {
                dbManager.Open();
                dbManager.ExecuteNonQuery(CommandType.Text, "TRUNCATE TABLE LeveringItem");
                succeed = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
            return succeed;
        }

    }
}
